package com.rongmai.web;

import com.rongmai.web.utils.SpringUtil;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Created by @author yihui in 14:26 19/8/16.
 */
@EnableWebMvc
@SpringBootApplication
@EnableAspectJAutoProxy
@MapperScan("com.rongmai.db.mapper")
@ServletComponentScan(basePackages = "com.rongmai.web.filter")
public class WebApplication implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 请注意下面这个映射，将资源路径 /ts 下的资源，映射到根目录为 /ts的访问路径下
        // 如 ts下的ts.html, 对应的访问路径为   /ts/ts
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
    }

    public static void main(String[] args) {
        SpringApplication.run(WebApplication.class);
    }

    @Component
    @Slf4j
    public static class PrintBanner implements ApplicationListener<ApplicationReadyEvent> {

        @Override
        public void onApplicationEvent(ApplicationReadyEvent event) {
            // 启动信息打印
            log.info("=================boot start finish=================");
            log.info("withProfile:"+ SpringUtil.getActiveProfile());
        }
    }
}
